# -*- coding: utf-8 -*-
# ****************************************************
# Author: yizuoliang
# Create: 2024/6/24
# Last Modified: 2024/6/24
# Last Editor:
# Filename: __init__.py
# Description: 
# ***************************************************
import secrets

from flask_login import LoginManager

from applications.models.user import User


def init_login_manager(app):
    secret_key = secrets.token_urlsafe(24)
    app.config['SECRET_KEY'] = secret_key
    login_manager = LoginManager()
    login_manager.init_app(app)

    # 创建一个回调函数,用户从会话中加载用户。LoginManager 会调用这个函数来获取当前登录的用户。
    @login_manager.user_loader
    def load_user(user_id):
        return User.get(user_id)
